﻿using System;
using System.Windows;
using System.Windows.Input;
using CrateMayhem.Common.ViewModel;
using GameControlViewModel = CrateMayhem.Desktop.ViewModel.GameControlViewModel;

namespace CrateMayhem.Desktop
{
    public sealed partial class GameControls
    {
        private readonly GameControlViewModel model;

        public GameControls()
        {
            InitializeComponent();
            
            try
            {
                model = (GameControlViewModel)Global.Container.Resolve<ViewModelBase>(typeof(GameControlViewModel).Name);
                DataContext = model;

                if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                    Application.Current.MainWindow.KeyDown += OnKeyDown;
            }
            catch (Exception)
            {
                
            }
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            model.PerformKeyPress(e.Key);
        }
    }
}
